/*jslint node:true*/
'use strict';
var fs = require('fs');
var data = '';

var readerStream = fs.createReadStream('input.txt');
readerStream.setEncoding('UTF8');

var writerStream = fs.createWriteStream('output.txt');

readerStream.on('data', function (chunk) {
    data += chunk;
});
readerStream.on('end', function () {
    console.log(data);
    writerStream.write(data, 'UTF8');
    writerStream.end();
    writerStream.on('finish', function () {
        console.log('finish to write');
    });
    writerStream.on('error', function (err) {
        console.log(err.stack);
    });
});
readerStream.on('error', function (err) {
    console.log(err.stack);
});

console.log('program end');